﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Abigail.Model
{
    public class User
    {
        #region InstanceVariables
        private string initials;
        public string Initials
        {
            get { return initials; }
            set { initials = value.ToUpper(); }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        string password;
        public string PasswordInSHA1
        {
            get { return password; }
            set { password = value.ToUpper(); }
        }
        public string PasswordInText
        {
            set { password = GenerateSHA1(value); }
        }

        string email;
        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        string phone;
        public string Phone
        {
            get { return phone; }
            set { phone = value; }
        }

        bool activated;
        public bool Activated
        {
            get { return activated; }
            set { activated = value; }
        }

        DateTime updated;
        public DateTime Updated
        {
            get { return updated; }
            set { updated = value; }
        }

        #endregion

        public User()
        {
            initials = "";
            name = "";
            password = "";
            email = "";
            phone = "";
            activated = true;
        }

        public User(string givenInitials, string givenName, string givenPasswordInSHA1, string givenEmail, string givenPhone, bool givenActivated)
        {
            initials = givenInitials;
            name = givenName;
            password = givenPasswordInSHA1;
            email = givenEmail;
            phone = givenPhone;
            activated = givenActivated;
        }

        private string GenerateSHA1(string input)
        {
            return BitConverter.ToString(SHA1Managed.Create().ComputeHash(Encoding.Default.GetBytes(input))).Replace("-", "");
        }

        public bool VerifyPassword(string input)
        {
            if (GenerateSHA1(input) == password)
                return true;
            else
                return false;
        }

    }
}
